package com.hzp.micromall.order.controller;

import com.hzp.micromall.common.core.api.CommonResult;
import com.hzp.micromall.order.entity.OmsOrderSetting;
import com.hzp.micromall.order.service.OmsOrderSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author houzipeng
 * @Date 2022/2/28 21:48
 * @Version 1.0
 */
@Controller
@Api(tags = "订单设置管理")
@RequestMapping("/order/orderSetting")
public class OmsOrderSettingController {
    @Autowired
    private OmsOrderSettingService orderSettingService;

    @ApiOperation("获取订单设置")
    @RequestMapping(value = "/getSetting", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<OmsOrderSetting> getSetting() {
        OmsOrderSetting orderSetting = orderSettingService.getSetting();
        return CommonResult.success(orderSetting);
    }

    @ApiOperation("修改指定订单设置")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@PathVariable Long id, @RequestBody OmsOrderSetting orderSetting) {
        int count = orderSettingService.update(id, orderSetting);
        if (count > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}
